#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int pp(void *a, void *b)
{
	int i = *((int *)a);
	int j = *((int *)b);
	printf("%d, %d\n", i, j);
	return 0;
}

int print(void *array, int len, int size, void *t, int (*fun)(void *, void *))
{
	int i;
	int *p = (int *)array;
	for (i = 0 ; i < 5; i++)
		printf("%d\n", *(p+i));
	for (i = 0; i < 5; i++)
		fun(array+i*size, t);
}
int void_pointer_array()
{
	void *p = malloc(sizeof(void *)*10), *p1;
	printf("%ld, %ld\n", sizeof(void *), sizeof(void));
	p = (void *)strdup("abc");
	p1 = p + 1;
	p1 = (void *)strdup("def");
	printf("%p:%s, %p:%s\n", p, (char *)p, p1, (char *)p1);
	return 0;
}
int long_array_as_pointer()
{
	long *p = malloc(sizeof(long)*10);
	printf("%ld, %ld\n", sizeof(long), sizeof(void));
	p[0] = (long)strdup("abc");
	p[1] = (long)strdup("def");
	printf("%p:%s, %p:%s\n", p, (char *)p[0], p+1, (char *)p[1]);
	return 0;
}

int data[4] = {1};
int main()
{
	int t = 8;
	int a[5] = {1, 2, 3, 4, 5};
	print((void *)a, 5, sizeof(int), &t, pp);
	void *p = a;
	int  *ip = a;
	printf("%p, %d, %p, %d, %p, %p\n", p,*(int *)p, p++,*(int *)p, ip, ip++);
	p = a;
	for (t = 0; t < 5; t++)
		printf( "%d\n", *((int *)(p+sizeof(int)*t)));
	void_pointer_array();
	long_array_as_pointer();
	for (t = 0; t < 4; t++)
		printf("%d\n", data[t]);
	while(1);
	*((char *)0) = 123;
	return 0;
}
